﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/BE/_Admin_Layout.cshtml";
}
<style>
    #runpanel {
        padding: 10px;       
    }
    #des {
        float: left; 
        width:60%;
        padding: 10px;
    }
    
</style>
<script type="text/javascript">
    $(document).ready(function () {
        $('#onrank').click(function () {
            if ($(this).is(":checked") == false) {
                $('#rankall').attr({ disabled: 'disabled' });
            } else {
                $('#rankall').removeAttr("disabled");
            }
        });
        $('#rankall').click(function () {
            $("#dialog").dialog({
                resizable: false,
                height: 250,
                modal: true,
                buttons: {
                    "Có": function () {
                        //$(this).dialog("close");
                        var url = "@Url.Action("RankSchool","ReferenceStandard")";
                        window.location = url;
                        $(this).dialog("close");
                    },
                    "Không": function () {
                        $(this).dialog("close");
                    }
                }
            });
        });
    });
</script>
<article class="module width_3_quarter">
    <div id="ServiceTable"></div>
</article>
<article class="module width_3_quarter">
    <header>
        <h3>Thực thi tác vụ</h3>
    </header>
    <div id="runpanel">
        <div id="des">
            <input type="checkbox" id="onrank">Xếp hạng lại các trường sau khi đã thay đổi trọng số của dịch vụ
        </div>
        <button style="float: right;" id="rankall" disabled="disabled">
            <span class="ui-button-text">Xếp hạng các trường</span>
        </button>
        
        <div style="clear:both"></div>
    </div>
</article>
<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jtable plugin
        $('#ServiceTable').jtable({
            //...
            selecting: true, //Enable selecting
            multiselect: true, //Allow multiple selecting
            selectingCheckboxes: true, //Show checkboxes on first column
            openChildAsAccordion: true,
            selectOnRowClick: true, //Enable this to only select using checkboxes
            paging: true,
            pageSize: 10,
            defaultSorting: 'ServiceName ASC',
            sorting: true,

            title: 'Danh sách các dịch vụ',
            actions: {
                listAction: '@Url.Action("ListService")',
                deleteAction: '@Url.Action("DeleteService")',
                updateAction: '@Url.Action("UpdateService")',
                createAction: '@Url.Action("CreateService")'
            },
            fields: {
                ServiceID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                ServiceName: {
                    title: 'Tên dịch vụ',
                    width: '15%',
                    inputClass: 'validate[required,maxSize[50]]' 

                },
                Weight:
                {
                    title: 'Trọng số',
                    inputClass: 'validate[required,custom[float],max[0.5],min[0.1]'                  
                },
                SchoolCount: {
                    title: 'Số trường có dịch vụ',
                    width: '15%',
                    create: false,
                    edit: false
                }
            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                data.form.validationEngine();
                
            },
            //Validate form when it is being submitted
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            //Dispose validation logic when form is closed
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            },
            //Register to selectionChanged event to hanlde events
            selectionChanged: function () {
                //Get all selected rows
                var $selectedRows = $('#ServiceTable').jtable('selectedRows');

                $('#SelectedRowList').empty();
                if ($selectedRows.length > 0) {
                    //Show selected rows
                    $selectedRows.each(function() {
                        var record = $(this).data('record');
                        $('#SelectedRowList').append(
                            '<b>PersonId</b>: ' + record.PersonId +
                                '<br /><b>Name</b>:' + record.Name + '<br /><br />'
                        );
                    });
                } else {
                    //No rows selected
                    $('#SelectedRowList').append('No row selected! Select rows to see here...');
                }
            }
        });

        //Re-load records when user click 'load records' button.
        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#ServiceTable').jtable('load', {
                keywords: $('#name').val(),
            });
        });

        //Load person list from server
        $('#ServiceTable').jtable('load');
        
        //
        //Delete selected students
        $('#DeleteAllButton').button().click(function () {
            var $selectedRows = $('#ServiceTable').jtable('selectedRows');
            $('#ServiceTable').jtable('deleteRows', $selectedRows);
        });
    });

</script>

